#include "testnode.h"

TestNode::TestNode() :
    QObject()
{
    question = "";
    reals = 0;
}

TestNode::TestNode(const TestNode &testNode) :
    QObject()
{
    question = testNode.question;
    reals = testNode.reals;
    answers = testNode.answers;
}

TestNode &TestNode::operator =(const TestNode &testNode)
{
    question = testNode.question;
    reals = testNode.reals;
    answers = testNode.answers;
    return *(this);
}

void TestNode::setQuestion(const QString &question)
{
    this->question = question;
}

void TestNode::addAnswer(const QString &answer, quint16 real)
{
    quint32 n = count();
    answers.append(answer);
    reals += real * std::pow(2, n);
}

void TestNode::setReals(quint16 reals)
{
    this->reals = reals;
}

void TestNode::setAnswers(const QStringList &answers)
{
    this->answers = answers;
}

QString TestNode::getQuestion() const
{
    return question;
}

QStringList TestNode::getAnswers() const
{
    return answers;
}

bool TestNode::checkAnswers(quint16 r_answers)
{
    return (reals == r_answers);
}

quint16 TestNode::getReals() const
{
    return reals;
}

quint32 TestNode::count() const
{
    return answers.count();
}

QDataStream& operator <<(QDataStream &out, const TestNode &testNode)
{
    out << testNode.getQuestion() << testNode.getAnswers() << quint16(testNode.getReals());
    return out;
}

QDataStream& operator >>(QDataStream &in, TestNode &testNode)
{
    QString quest = "";
    QStringList answ;
    quint16 real = 0;

    in >> quest >> answ >> real;
    testNode.setQuestion(quest);
    testNode.setAnswers(answ);
    testNode.setReals(real);
    return in;
}
